package com.lab.controller.user;


import com.lab.common.Result;
import com.lab.dto.DailyProgressDTO;
import com.lab.service.DailyMemberProgressService;
import com.lab.vo.DailyProgressVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student" +
        "/daily/progress")
@Slf4j
@Api(tags = "<任淑志用户端>成员进度-日进度表")
public class userDailyMemberProgressController {

    @Autowired
    private DailyMemberProgressService dailyMemberProgressService;

    @PostMapping("/daily")
    @ApiOperation("新增每日进度")
    public Result<?> addDailyProgress(@RequestBody DailyProgressDTO dto) {
        dailyMemberProgressService.addDailyProgress(dto);
        return Result.success("新增成功");
    }

    @GetMapping("/member/{memberName}")
    @ApiOperation("前端根据成员名字查询日进度详情")
    public Result<List<DailyProgressVO>> getByMemberName(@PathVariable String memberName) {
        List<DailyProgressVO> voList = dailyMemberProgressService.getByMemberName(memberName);
        if (voList == null || voList.isEmpty()) {
            return Result.error("未找到成员名为\"" + memberName + "\"的进度记录");
        }
        System.out.println("传入的成员名字：" + memberName);
        return Result.success(voList); // 前端拿到数组形式的结果
    }
}
